require 'net/http'
require 'json'

def parse_url(url)
  response = Net::HTTP.get_response(URI.parse(url))

  result = JSON.parse(response.body)

  result.each { |channel|
    channel.each { |key, value|
      puts "<key>#{key}</key>"
      puts "<string>#{value}</string>"
    }
  }
end

def list_channels(spaceId)
  urlSpace = "http://server.parleys.com/rest/v2/spaces/#{spaceId}/channels.form"
  parse_url(urlSpace)
end

def list_presentations(spaceId, channelId)
  urlChannel = "http://server.parleys.com/rest/v2/spaces/#{spaceId}/channels/#{channelId}/presentations.form"
  parse_url(urlChannel)
end

def list_assets(spaceID, channelId, presentationId)
  urlAsset = "http://server.parleys.com/rest/v2/spaces/#{spaceId}/channels/#{channelId}/presentations/#{presentationId}/assets.json"
  parse_url(urlAsset)
end

def get_file(urlFile)
  responseFile = http.get(urlFile)
  open("toto", "wb") do |file|
    file.write(reponseFile.body)
  end
end

urlSpaces = "http://server.parleys.com/rest/v2/spaces.form"
#parse_url(urlSpaces)
#list_channels(189)
list_presentations(189, 102906)
